It's not python code but.. maybe could be useful for you.

While ago - Using gpio and PWM - I did add some flash effects to every buttons on my bartop build.

check out this video

and you can find source code here.
https://github.com/losernator/rainbowLED

FYI My friend 'sana2dang' made original code for me and I just add little bit.
Although I am not using this any more and moved to RGB effect using Aruino :) but worth trying